Kinetis SDK API Reference Manual  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages

The section describes the programming interface of the DSPI slave mode Peripheral driver. More...

Data Structures

struct  dspi_slave_callbacks_t
 The set of callbacks for the DSPI slave mode. More...
 
struct  dspi_slave_state_t
 Runtime state of the DSPI slave driver. More...
 
struct  dspi_slave_user_config_t
 User configuration structure and callback functions for the DSPI slave driver. More...
 

Init and shutdown

dspi_status_t dspi_slave_init (uint32_t instance, dspi_slave_state_t *dspiState, const dspi_slave_user_config_t *slaveConfig)
 Initializes a DSPI instance for a slave mode operation. More...
 
void dspi_slave_shutdown (dspi_slave_state_t *dspiState)
 Shut down a DSPI instance. More...
 

DSPI Slave Driver

Overview

The DSPI slave peripheral driver supports using the SPI peripheral in slave mode.Data transfer is performed entirely through callback functions.

Runtime state of the DSPI slave driver

This struct holds data that the DSPI slave peripheral driver uses to communicate between the transfer function and the interrupt handler. The user needs to pass the memory for this structure and the driver will fill out the members.

Callbacks

To use this driver, first define application callbacks. These are the callback functions that are set in the dspi_slave_callbacks_t struct.The three callbacks are:

  • Data source
  • Data sink
  • Error notification
The first two callbacks are for sending and receiving data. The third callback is invoked if an error occurs.The prototypes for the three callbacks are:

status_t data_source(uint8_t * sourceWord, uint32_t instance);
status_t data_sink(uint8_t sinkWord, uint32_t instance);
void on_error(status_t error, uint32_t instance);
All callbacks are invoked from the IRQ state.

Setup

To initialize the DSPI slave driver, first create and fill in a dspi_slave_user_config_t struct. This struct defines the callbacks and the data format settings for the SPI peripheral. The struct is not required after the driver is initialized and can be allocated on the stack. The user also must pass the memory for the run-time state structure.Here is an example of a config struct definition:

/* Set up and init the slave */
dspi_slave_state_t dspiSlaveState;
dspi_slave_user_config_t slaveUserConfig;
slaveUserConfig.callbacks.dataSink = data_sink;
slaveUserConfig.callbacks.dataSource = data_source;
slaveUserConfig.callbacks.onError = on_error;
slaveUserConfig.dataConfig.bitsPerFrame = 16;
slaveUserConfig.isModifiedTimingFormatEnabled = false;
dspi_slave_init(slaveInstance, &slaveUserConfig, &dspiSlaveState);

Data Structure Documentation

struct dspi_slave_callbacks_t

The user creates the function implementations.

Data Fields

dspi_status_t(* dataSource )(uint8_t *sourceWord, uint32_t instance)
 Callback to get word to transmit. More...
 
dspi_status_t(* dataSink )(uint8_t sinkWord, uint32_t instance)
 Callback to put received word. More...
 
void(* onError )(dspi_status_t error, uint32_t instance)
 Callback to report a DSPI error, such as an under-run or over-run error. More...
 

Field Documentation

dspi_status_t(* dspi_slave_callbacks_t::dataSource)(uint8_t *sourceWord, uint32_t instance)
dspi_status_t(* dspi_slave_callbacks_t::dataSink)(uint8_t sinkWord, uint32_t instance)
void(* dspi_slave_callbacks_t::onError)(dspi_status_t error, uint32_t instance)
struct dspi_slave_state_t

This struct holds data that is used by the DSPI slave peripheral driver to communicate between the transfer function and the interrupt handler. The user needs to pass in the memory for this structure and the driver fills out the members.

Data Fields

uint32_t instance
 DSPI module instance number.
 
dspi_slave_callbacks_t callbacks
 Application/user callbacks.
 
uint32_t bitsPerFrame
 Desired number of bits per frame.
 
struct dspi_slave_user_config_t

Data Fields

dspi_slave_callbacks_t callbacks
 Application/user callbacks. More...
 
dspi_data_format_config_t dataConfig
 Data format configuration structure.
 

Field Documentation

dspi_slave_callbacks_t dspi_slave_user_config_t::callbacks

Function Documentation

dspi_status_t dspi_slave_init ( uint32_t  instance,
dspi_slave_state_t dspiState,
const dspi_slave_user_config_t slaveConfig 
)

This function saves the callbacks to the run-time state structure for a later use in the interrupt handler. It also ungates the clock to the DSPI module, initializes the DSPI for slave mode, and enables the module and corresponding interrupts. Once initialized, the DSPI module is configured in slave mode and ready to receive data from the SPI master. This is an example to set up the dspi_slave_state_t and the dspi_slave_user_config_t parameters and to call the dspi_slave_init function by passing in these parameters:

dspi_slave_state_t dspiSlaveState; <- the user simply allocates memory for this struct
dspi_slave_user_config_t slaveUserConfig;
slaveUserConfig.callbacks.dataSink = data_sink; <- set to user implementation of function
slaveUserConfig.callbacks.dataSource = data_source; <- set to user implementation of function
slaveUserConfig.callbacks.onError = on_error; <- set to user implementation of function
slaveUserConfig.dataConfig.bitsPerFrame = 16;
dspi_slave_init(slaveInstance, &slaveUserConfig, &dspiSlaveState);
*
Parameters
instanceThe instance number of the DSPI peripheral.
dspiStateThe pointer to the DSPI slave driver state structure.
userThe configuration structure dspi_slave_user_config_t, including the callbacks.
Returns
An error code or kStatus_DSPI_Success.
void dspi_slave_shutdown ( dspi_slave_state_t dspiState)

Resets the DSPI peripheral, disables the interrupt to the core, and gates its clock.

Parameters
dspiStateThe pointer to the DSPI slave driver state structure.